package org.example.bookstore.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.example.bookstore.custom.ResultVO;
import org.example.bookstore.pojo.DO.Cart;
import org.example.bookstore.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "购物车Api")
@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/cart")
public class CartController {
    @Autowired
    private CartService cartService;

    /*
     * 向购物车添加商品
     * */
    @Operation(summary = "添加购物车商品")
    @PostMapping("/add")
    public ResultVO<?> CartAdd(@RequestBody Cart cart){
        return cartService.insertGoods(cart);
    }
    /*
     * 查询购物车列表
     * */
    @Operation(summary = "查询用户购物车商品")
    @GetMapping("/list")
    public ResultVO<?> SelectCartList(@Parameter(name = "id", description = "用户id") @RequestParam Integer id){
        return ResultVO.success("购物车商品列表",cartService.selectCartList(id));
    }
    /*
     * 删除购物车商品
     * */
    @Operation(summary = "删除购物车商品")
    @GetMapping("/clear")
    public ResultVO<?> DeleteGoods(@Parameter(name = "id", description = "购物车id") @RequestParam Integer id){
        return cartService.deleteCartGoods(id);
    }
}
